<?php
session_start();
if (isset($_POST['op'])){
    include '../c/config.php';
function http_post_json($url, $jsonStr)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json; charset=utf-8',
            'Content-Length: ' . strlen($jsonStr)
        )
    );

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
 
    return array($httpCode, $response);
}
   
   $openid=addslashes(trim($_POST['op']));
   $sourceId='ac011'; 
   $sourcetype='695';
   $regsubchannel='695';
   $name=addslashes(trim($_POST['name']));
   $phone=addslashes(trim($_POST['p']));
   $yu=addslashes(trim($_POST['yu']));
   $yu2=addslashes(trim($_POST['yu2']));
   $post_data = array(
  'phone' => $phone,
  'name' => $name,
  'sourcetype' => $sourcetype,
  'regsubchannel' => $regsubchannel,
  'code' => '123456',
  'babybirth' => $yu,
  //'babybirth' => '2015-01-25',
  'sourceId' => $sourceId
);
   if (!empty($_POST['yu2'])) {
       $post_data['secbabybirth']=$yu2;
   }
  
   $getData=http_post_json('https://nc-api-test.51wom.com/api/customerUserMountainClimbing/register', json_encode($post_data,JSON_UNESCAPED_UNICODE));
   $theData=json_decode($getData[1], true);

   $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
   $mysqli->query("insert into user_loginreg_log(openid,lei,msg,createtime) values('".$openid."','reg','".$getData[1]."','".date("Y-m-d H:i:s")."') ");
 
   if (isset($theData['data']) && (105 == $theData['data'] || 103 == $theData['data'] || 102 == $theData['data'] || 101 == $theData['data'] ) ) {
         $mysqli->query("update ".$tableVer."_users set realname='".$name."',phone='".$phone."',yu='".$yu."',yu2='".$yu2."'  where openid='".$openid."' ");
         echo json_encode(array('s' =>'y' ,'t'=>'finish'));
         exit;
   }else{
      echo json_encode(array('s' =>'n' ,'t'=>'fail'));
      exit;
   }
   if (NULL == $theData['data'] && 104 == $theData['data']) {  
          echo json_encode(array('s' =>'n' ,'t'=>'fail'));
          exit;
   }
    
    
    
    
     
    echo json_encode(array('s'=>'y','p'=>$userPai,'up'=>$userPaiNum,'fen'=>$userFen));
    
}
?>
